import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { resolve } from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import config from "./config/env.js";
import { fileURLToPath, URL } from "node:url";
import { svgBuilder } from "./src/plugins/svgBuilder";

export default defineConfig({
  plugins: [
    vue(),
    svgBuilder("./src/assets/icons/svg/"),
    vueJsx(),
    AutoImport({
      resolvers: [
        // 自动导入 Element Plus 组件
        ElementPlusResolver(),
      ],
    }),
    Components({
      resolvers: [
        // 自动导入 Element Plus 组件
        ElementPlusResolver(),
      ],
    }),
  ],
  //去掉所有console debugger
  esbuild: {
    drop: ["console", "debugger"],
  },
  css: {
    postcss: {
      plugins: [],
    },
  },
  server: {
    host: 'localhost',
		port: '5173',
    proxy: {
      "/api": {
        target: config.API_BASE_URL + "/api",
        ws: true,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
  resolve: {
    //路径配置@符号识别
    // zwy配置
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});
